<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * MY_DB_sqlsrv_driver
 *
 * DB extension class to give various parsing
 * methods.  Generally speaking, these are
 * standard methods for converting a DB query
 * into an array/result.
 * 
 * This only appears to work when hosted on a
 * Windows server.  No Linux/Mac driver for
 * SQLSRV currently exists
 *
 * @author Simon Emms <simon@simonemms.com>
 */
class MY_DB_sqlsrv_driver extends CI_DB_sqlsrv_driver {
    
    
    
    public $connection = 'sqlsrv_connect';
    
    
    
    /**
     * Non-persistent database connection
     * 
     * Identical to parent function, but displays
     * an error
     *
     * @access	private called by the base class
     * @return	resource
     */
    public function db_connect() {
        if(function_exists('sqlsrv_connect')) {
            /* Run the function */
            $character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set;

            $connection = array(
                'UID' => empty($this->username) ? '' : $this->username,
                'PWD' => empty($this->password) ? '' : $this->password,
                'Database' => $this->database,
                'ConnectionPooling' => 0, /* I can't get permenant connection working */
                'CharacterSet' => $character_set,
                'ReturnDatesAsStrings' => 1
            );

            /* If the username and password are both empty, assume this is a 'Windows Authentication Mode' connection. */
            if(empty($connection['UID']) && empty($connection['PWD'])) {
                unset($connection['UID'], $connection['PWD']);
            }

            return sqlsrv_connect($this->hostname, $connection);
        } else {
            return false;
        }
    }
    

    /**
     * Persistent database connection
     * 
     * Identical to parent function, but displays
     * an error if function doesn't exist
     *
     * @access	private called by the base class
     * @return	resource
     */
    public function db_pconnect() {
        /* I've never gotten the pconnect working -  */
        return $this->db_connect();
    }
    
    
    
    
    
    
    
    public function num_rows() {
        echo '<pre>'.print_r(func_get_args(), true).'</pre>';exit;
    }
}
?>